package com.algorithm.List;

public abstract class AbstractList<E> implements List<E>{
    protected int size;
    protected static final int ELEMENT_NOT_FOUND = -1;

    public int size() {
        return size;
    }

    public boolean isEmpty() {
        return size == 0;
    }

    public boolean contains(E element) {
        return indexOf(element) != ELEMENT_NOT_FOUND;
    }

    public void add(E element) {
        add(size,element);
    }

    protected void outOfBounds(int index) {
        throw new IndexOutOfBoundsException("Index:" + index + ", Size:" + size);
    }

    protected void rangeCheck(int index) {
        if (index >= size || index < 0) {
            outOfBounds(index);
        }
    }

    protected void rangeCheckforAdd(int index) {
        if (index > size || index < 0) {
            outOfBounds(index);
        }
    }
}
